package com.ruoyi.web.controller;
/**
 * ClassName: PublishController <br/>
 * Description: <br/>
 * date: 2020/3/24 14:35<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import com.ruoyi.system.domain.Message;
import com.ruoyi.system.service.IMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

/**
 * @program: ruoyi
 * @description:
 * @author: hesion
 * @create: 2020-03-24 14:35
 **/
@Controller
public class PublishController {
    String prefix = "page";
    @Autowired
    IMsgService msgService;

    @PostMapping("/publish")
    public String doPublish(@RequestParam(value = "desc", required = false) String desc,
                            @RequestParam(value = "name", required = false) String name,
                            HttpServletRequest request,
                            Model model) {
        Message msg = new Message();
        msg.setCreateBy(name);
        msg.setCreateTime(LocalDateTime.now());
        msg.setDesc(desc);

        int doPublish = msgService.doPublish(msg);
        if (doPublish > 0) {
            model.addAttribute("msg", "留言成功");
            return prefix + "/msg";
        } else {
            model.addAttribute("msg", "留言失败");
            return prefix + "/msg";
        }

    }
}
